package com.lihao.sam.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lihao.sam.dao.LtemInformationRegistrationDao;
import com.lihao.sam.dao.WarehousingRegistrationOfArticlesDao;
import com.lihao.sam.entity.xiaobei.LtemInformationRegistration;
import com.lihao.sam.entity.xiaobei.WarehousingRegistrationOfArticles;
import com.lihao.sam.service.intf.LtemInformationRegistrationService;
import com.lihao.sam.service.intf.WarehousingRegistrationOfArticlesService;
import com.lihao.sam.vo.PageVo;
import com.lihao.sam.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author yifu
 * @date2022/11/22 19:51
 */
@Service
public class WarehousingRegistrationOfArticlesServiceImpl implements WarehousingRegistrationOfArticlesService {

    @Resource
    private WarehousingRegistrationOfArticlesDao dao;
    @Override
    public R add(WarehousingRegistrationOfArticles warehousingRegistrationOfArticles) {
        //1.校验参数
        if(warehousingRegistrationOfArticles!=null){
            //2.操作数据库
            if(dao.add(warehousingRegistrationOfArticles)>0){
                return R.ok();
            }
        }
        return R.fail();
        }

    @Override
    public R update(WarehousingRegistrationOfArticles warehousingRegistrationOfArticles) {
        //1.校验参数
        if(warehousingRegistrationOfArticles!=null){
            //2.操作数据库
            if(dao.update(warehousingRegistrationOfArticles)>0){
                return R.ok();
            }
        }
        return R.fail();
    }

    @Override
    public R delete(int id) {
        //1.校验参数
        if(id>0){
            //2.操作数据库
            if(dao.delete(id)>0){
                return R.ok();
            }
        }
        return R.fail();
    }

    @Override
    public R delBatch(int[] array) {
        if (dao.delBatch(array) > 0) {
            return R.ok();
        }
        return R.fail();
    }

    @Override
    public PageVo queryPage(String goodsid,String goodsname, String specification, int page, int limit) {
        //1.开启分页，设置对应的页码
        PageHelper.startPage(page,limit);
        //2.开始查询
        PageInfo<WarehousingRegistrationOfArticles> pageInfo=new PageInfo<>(dao.selectByWhere(goodsid, goodsname,specification));
        //3.返回对应的结果
        return PageVo.ok(pageInfo.getTotal(),pageInfo.getList());
    }


}
